package operation;

import book.BookList;

import java.util.Scanner;

//借阅书籍
public class BorrowOperation implements IOperation{
    @Override
    public void word(BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("借阅书籍");
        System.out.println("请选择查询方式:>");
        System.out.println("1.作者    2.书名");
        int choice = scanner.nextInt();
        if(choice == 1){
            System.out.println("请输入作者名字:>");
            String author = scanner.next();
            int pos = bookList.getUsedSize();
            for (int i = 0; i < pos; i++) {
                if(author.equals(bookList.getBook(i).getAuthor())){
                    System.out.println("借阅成功");
                    bookList.getBook(i).setBorrowed(true);
                    return;
                }

            }
            System.out.println("无此书");
        }else if(choice == 2){
            System.out.println("请输入书名:>");
            String name = scanner.next();
            int pos = bookList.getUsedSize();
            for (int i = 0; i < pos; i++) {
                if(name.equals(bookList.getBook(i).getName())){
                    System.out.println("借阅成功");
                    bookList.getBook(i).setBorrowed(true);
                    return;
                }

            }
            System.out.println("无此书");
        }else{
            System.out.println("输入错误");
            return;
        }
    }
}
